package org.nutboat.core;

public class DataEvent extends GameEvent<GameData> {
	private final String valueName;
	private final Object oldValue;
	private final Object newValue;
	
	public DataEvent(GameData source, 
			String valueName, 
			Object oldValue, 
			Object newValue) {
		super(source);
		this.valueName = valueName;
		this.oldValue = oldValue;
		this.newValue = newValue;
	}
	
	public String getValueName() {
		return valueName;
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getOldValue(Class<T> type) {
		if (oldValue.getClass() == type) {			
			return (T) oldValue;
		}
		return null;
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getNewValue(Class<T> type) {
		if (oldValue.getClass() == type) {			
			return (T) newValue;
		}
		return null;
	}
}